package com.zx.cloud.security;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.common.serialization.StringDeserializer;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

/**
 * @author zhaoxuan
 * @date 2022-01-19 10:04
 **/
public class KafkaMain {

    public static void main(String[] args) {
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmm");
        String now = format.format(new Date());
        List<String> dateStep = getDateStep(now, "00", "24", "180");
        int indexOf = dateStep.indexOf(now);
        System.out.println(indexOf);
        System.out.println(dateStep.get(indexOf-1));

    }
    public static String decodeUTF8Str(String xStr) throws UnsupportedEncodingException {
        return URLDecoder.decode(xStr.replaceAll("\\\\x", "%"), "utf-8");
    }

    public static List<String> getDateStep(String nowDate,String s,String e ,String step) {
        List<String> list = new ArrayList<>();
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmm");
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmm");

        Calendar c = Calendar.getInstance();

        Calendar end = Calendar.getInstance();
        try {
            Date date = format.parse(nowDate);
            c.setTime(date);
            c.set(Calendar.HOUR_OF_DAY, Integer.parseInt(s));
            c.set(Calendar.MINUTE, 0);
            list.add(dateFormat.format(c.getTime()));

            end.setTime(date);
            if ("24".equals(e)) {
                e = "00";
            }
            end.add(Calendar.DAY_OF_YEAR, 1);
            end.set(Calendar.HOUR_OF_DAY, Integer.parseInt(e));

            while (c.getTimeInMillis() < end.getTimeInMillis()) {
                c.add(Calendar.SECOND, Integer.parseInt(step));
                list.add(dateFormat.format(c.getTime()));
            }

        } catch (ParseException pe) {
            pe.printStackTrace();
        }

        return list;
    }

}
